<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2018 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: http://www.dsxcms.com
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2018-11-29
 * Time: 11:26
 */

namespace App\Library\Mall\Shop;


use App\Models\Shop;

trait CatlogActions
{
    /**
     * @param Shop $shop
     * @return array
     */
    protected function fetchShopCtlogs(Shop $shop)
    {
        $catlogs = [];
        foreach ($shop->catlogs()->with('children')->where('fid', 0)->get(['catid', 'name']) as $catlog)
        {
            if ($catlog->children->count())
            {
                foreach ($catlog->children as $children)
                {
                    $catlogs[] = [
                        'catid'=>$children->catid,
                        'name'=>$catlog->name.'-'.$children->name,
                    ];
                }
            } else {
                $catlogs[] = [
                    'catid'=>$catlog->catid,
                    'name'=>$catlog->name
                ];
            }
        }

        return $catlogs;
    }
}
